package org.yi.fc.controller.admin.friendlink;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yi.fc.controller.base.BaseController;
import org.yi.fc.entity.FFriendLink;
import org.yi.fc.model.Pager;
import org.yi.fc.validator.admin.FriendLinkValidator;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Page;

public class FriendLinkController extends BaseController {
	
	private static final Logger logger = LoggerFactory.getLogger(FriendLinkController.class);
	
	public void add() {
		logger.trace("add friend link by {} method ...", getHttpMethod());
		if(isGetMethod()){
			render("add.html");
		} else if(isPostMethod()) {
			doAdd();
		}
	}
	
	@Before(FriendLinkValidator.class)
	public void doAdd() {
		new FFriendLink().save(getRequest());
		redirect(getAttrForStr("ctx") + "/admin/friendlink/index");
	}
	
	public void index() {
		logger.trace("friend link ...");
		
		Pager pager = getPager();
		Page<FFriendLink> page = FFriendLink.dao.getPager(pager);
		
		setAttr("page", page);
		render("list.html");
	}

}
